<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\admin\logic;

use app\common\model\GamesLog;

/**
 * 应用庄家逻辑
 */
class Appcan extends AdminBase
{
    
  
    
    /**
     * 获取应用庄家列表
     */
    public function getAppcanList($where = [], $field = 'a.*', $order = '')
    {
        
        $this->modelApplicationBanker->alias('a');
        




        $list=$this->modelApplicationBanker->getList($where, $field, $order);

        $this->modelApplicationBanker->alias('a');
        $count=$this->modelApplicationBanker->where($where)->count();
        return ['list'=>$list,'count'=>$count];
    }

    /**
     * 获取应用庄家列表
     */
    public function getAccountList($data = [], $field = 'a.*', $order = '')
    {
        !empty($data['search_data']) && $where['a.name|b.username'] =$data['search_data'];
        $where['a.type']=['in',[1,2]];

        $list = GamesLog::alias('a')->field($field)->join('__MEMBER__ b', 'a.user_id = b.id')->join('__APPLICATION_BANKER__ g', 'a.app_id = g.id')->where($where)->order($order)->paginate(10, false, ['query' => $data]);
        $count = GamesLog::alias('a')->field($field)->join('__MEMBER__ b', 'a.user_id = b.id')->join('__APPLICATION_BANKER__ g', 'a.app_id = g.id')->where($where)->count();
        return ['list'=>$list,'count'=>$count];
    }


    
    /**
     * 获取应用庄家列表搜索条件
     */
    public function getWhere($data = [])
    {
        
        $where = [];
        


        return $where;
    }
    
    /**
     * 应用庄家信息编辑
     */
    public function AppcanEdit($data = [])
    {

//        $validate_result = $this->validateAppcan->scene('edit')->check($data);
//
//        if (!$validate_result) {
//
//            return [RESULT_ERROR, $this->validateAppcan->getError()];
//        }
        $url = url('AppcanList');


        $result = $this->modelApplicationBanker->setInfo($data);
        
        $handle_text = empty($data['id']) ? '新增' : '编辑';
        
        $result && action_log($handle_text, '应用庄家' . $handle_text . '，name：' . $data['name']);
        
        return $result ? [RESULT_SUCCESS, '应用庄家操作成功', $url] : [RESULT_ERROR, $this->modelApplicationBanker->getError()];
    }

    /**
     * 获取应用庄家信息
     */
    public function getAppcanInfo($where = [], $field = 'a.*,c.name as category_name')
    {
        
        $this->modelApplicationBanker->alias('a');


        
        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];

        
        return $this->modelApplicationBanker->getInfo($where, $field);
    }
    


    
    /**
     * 应用庄家删除
     */
    public function AppcanDel($where = [])
    {
        
        $result = $this->modelApplicationBanker->deleteInfo($where);
        
        $result && action_log('删除', '应用庄家删除，where：' . http_build_query($where));
        
        return $result ? [RESULT_SUCCESS, '应用庄家删除成功'] : [RESULT_ERROR, $this->modelApplicationBanker->getError()];
    }

    /**
     * 应用庄家删除
     */
    public function update_info($where = [])
    {

        //dd($where);

        $result = $this->modelApplicationBanker->setInfo($where);


        return $result ? [RESULT_SUCCESS, '操作成功'] : [RESULT_ERROR, '操作失败'];
    }
}
